package com.kavenka.zhufengfm.app.client;

import com.kavenka.zhufengfm.app.http.HttpUtil;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

/**
 * Created by kavenka on 2015/9/25 0025.
 */
public class DiscoverClientAPI {
    public static final String API_POINT="http://mobile.ximalaya.com/mobile";
    public DiscoverClientAPI() {
    }

    /**
     * 获取发现-tab的标题数据
     * @return
     */
    public static JSONObject getDiscoverTabs(){
        JSONObject ret=null;
        String url=API_POINT+"/discovery/v1/tabs?device=android";
        byte[] bytes= HttpUtil.doGet(url);
        if (bytes != null) {
            try {
                String str=new String(bytes,"UTF-8");
                ret=new JSONObject(str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    /**
     * 获取发现-分类的数据
     * @return
     */
    public static JSONObject getDiscoverCategories(){
        JSONObject ret=null;
        String url=API_POINT+"/discovery/v1/categories?device=android&picVersion=10&scale=2";
        byte[] bytes= HttpUtil.doGet(url);
        if (bytes != null) {
            try {
                String str=new String(bytes,"UTF-8");
                ret=new JSONObject(str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    /**
     * 获取发现-推荐的数据
     * @param channel
     * @param includeActivity
     * @param includeSpecial
     * @param scale
     * @param version
     * @return
     */
    public static JSONObject getDiscoverRecommend(String channel,boolean includeActivity,boolean includeSpecial,String scale,String version){
        JSONObject ret=null;
        String url=API_POINT+"/discovery/v1/recommends?"
                +"channel="+channel
                +"&device=android"
                +"&includeActivity="+includeActivity
                +"&includeSpecial="+includeSpecial
                +"&scale="+scale
                +"&version="+version;
        byte[] bytes= HttpUtil.doGet(url);
        if (bytes != null) {
            try {
                String str=new String(bytes,"UTF-8");
                ret=new JSONObject(str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }
}
